#!/usr/bin/env python
# encoding:utf-8
'''
author: yangmingwei
'''
# from . import db
from datetime import datetime

#
# class TaskLog(db.Model):
#     __tablename__ = 'task_log'
#     id = db.Column(db.Integer, primary_key=True)
#     task_id = db.Column(db.String(16))
#     status = db.Column(db.Boolean)
#     exe_time = db.Column(db.DateTime, default=datetime.now)
#     cmd = db.Column(db.String(128))
#     stdout = db.Column(db.Text)
#
#     def to_json(self):
#         json_post = {
#             'id': self.id,
#             'task_id': self.task_id,
#             'status': self.status,
#             # 'exe_time': datetime.strftime(self.exe_time, '%Y-%m-%d'),
#             'exe_time': self.exe_time,
#             'cmd': self.cmd,
#             'stdout': self.stdout
#         }
#         return json_post


# 策略的类
class StrategyCls:

    def __init__(self, strategy):
        self.strategy_id = strategy[0]
        # 策略名称
        self.strategy_name = strategy[1]

        # 策略优先级（0 一般 1中等  2高）
        self.priority_lv = strategy[2]

        # 策略类型 （1 一次性 2长期）
        self.strategy_type = strategy[3]

        # 补丁分组id
        self.patch_group_id = strategy[5]

        # 资产分组id
        self.inventory_group_id = strategy[6]

        # 执行时间 e.g. {"week":"1","mode":2,"time":"22:08:00"}
        self.exec_time = strategy[14]

        self.trigger_switch = strategy[21]

        # 生效时间段, e.g. 20:37~21:37
        self.effective_time = strategy[22]

        # 策略分类：补丁分发类型  1测试，2正式，3人工，4普通文件
        self.patch_distribute = strategy[24]

        self.file_library_ids = strategy[9]

        self.save_path = strategy[10]

    def trans_json(self, input_json):
        self.strategy_name
        pass


# 资产类
class InventoryCls:
    def __init__(self, inventory=[None]*30):
        self.id = inventory[0]  # 资产编号
        self.name = inventory[2]    # 资产名称
        self.ip = inventory[5]  # 资产ip
        self.os = inventory[7]
        self.hostname = inventory[17]   # 资产域名
        self.username = inventory[15] # 登录用户名
        self.password = inventory[16] # 登录密码
        self.port = inventory[20] #登录端口

    def set_ip(self, ip):
        self.ip = ip

    def set_username(self, username):
        self.username = username

    def set_password(self, password):
        self.password = password

    def set_port(self, port):
        self.port = port




if __name__ == '__main__':
    print(InventoryCls().__dict__)